package com.example.spring.exercise.mapper;

import com.example.spring.exercise.service.dto.check.ClassInfo;
import com.example.spring.exercise.service.dto.check.DeptInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

/**
 * @author : zhayh
 * @Date : 2021-5-3 11:51
 * @Description:
 */

@Mapper
public interface CheckMapper {
    // 根据部门编码获取部门对象
    @Select("select * from niit_check_dep where dep_no=#{depNo}")
    DeptInfo getDeptByDeptNo(String depNo);

    // 根据班级名称查询班级
    @Select("select * from niit_check_class where class_name=#{className}")
    @Result(column = "dep_no", property = "deptInfo", one = @One(select =
            "getDeptByDeptNo", fetchType = FetchType.EAGER))
    ClassInfo getClassInfoByClassName(String className);

    // 定义根据班级编码,学期查询班级旷课总次数
    @Select("SELECT SUM(check_kk) AS class_absent_count FROM niit_check_main WHERE" +
            " class_no=#{classNo} AND term_no=#{termNo}")
    Integer getClassAbsentCountByClassNoAndTerm(@Param("classNo") String classNo,
                                                @Param("termNo") String termNo);

    // 定义根据班级编码,学期查询部门旷课总次数
    @Select("SELECT SUM( check_kk ) AS dep_absent_count FROM niit_check_main a," +
            "niit_check_class b WHERE a.class_no=b.class_no AND b.dep_no=#{depNo} AND term_no=#{termNo}")
    Integer getDepAbsentCountByClassNoAndTerm(@Param("depNo") String depNo,
                                              @Param("termNo") String termNo);

}
